<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/templates/common/taglib.jsp"%>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>解放军第三0五医院</title>
<%@include file="/WEB-INF/templates/common/common.jsp"%>
<script type="text/javascript" src="${basePath}/static/page/js/jqPaginator.js"></script>
<script  type="text/javascript" src="${basePath}/static/My97DatePicker/WdatePicker.js"></script>
<script  type="text/javascript" src="${basePath}/static/layer/layer.js"></script>
<link href="${basePath}/static/layer/layer_style.css" rel="stylesheet" type="text/css">
</head>
<body>

</head>
<body>
 <!--头部-->
 <%@include file="/WEB-INF/templates/common/header.jsp"%>

<!------导航条-->
 <%@include file="/WEB-INF/templates/common/navigation.jsp"%>


<div class="list_main lay_out">
 <div class="list_DH">


   <!--打印模块导航栏-->
 <%@include file="/WEB-INF/templates/common/printnav.jsp"%>
 </div>
 <div class="list_NR">
  <div class="loc">
   <h3>虚拟打印</h3>

  </div>
  <div class="list_con_table"> 
   <div class="search_table" style="position:relative">
    <ul>
    <li class="Label_1">病案所属人姓名：&nbsp;</li>
    <li class="Label_2"><input class="input_box" type="text" maxlength="10" name='patientName' id='patientName' value='' /></li>
    <li class="Label_1">病案所属人身份证：</li>
    <li class="Label_2"><input class="input_box" type="text" maxlength="20" name='patientCard' id='patientCard' value='' /></li>
    <li class="Label_1"  style="width:12%">申请人姓名：&nbsp;</li>
    <li class="Label_2"><input class="input_box" type="text"  maxlength="10" name='applyName' id='applyName' value='' /></li>
    <li class="Label_1">申请人身份证：</li>
    <li class="Label_2"><input class="input_box" type="text" maxlength="20"  name='applyCard' id='applyCard' value='' /></li>
    <li class="Label_1">诊疗记录标示：&nbsp;</li>
    <li class="Label_2"><input type="text"  maxlength="12"
					class="input_box" id="medicalRecord"/></li>
    
	 <li class="Label_1" style="width:12%">打印状态：&nbsp;</li> 
	 <li style="width:21%" class="Label_3">
     <input type="radio" class="radio_cl" checked="checked"  name='printCheck' id='' value='1' />未打印
      <input type="radio" class="radio_cl"  name='printCheck' id='' value='2' />已打印 
     </li> 
    <li class="Label_1">申请时间：&nbsp;<span class="Label_6">*</span></li>
     <li class="Label_2" style="width:400px;text-align:left">
     <input style="width:175px;margin-left:5px" class="input_box" id="timeStart" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" type="text"  name=''  value='' />
      - <input style="width:175px" class="input_box" id="timeEnd" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" type="text"  name=''  value='' />
     </li>
    <li class="Label_5">
     <a  href="javascript:queryPrint(0,10)">查询</a>
    </li>
    </ul>
   </div>
  </div>

 <table class="Search_tableList" cellpadding="0" cellspacing="0">
     
      <tr>
      <td class="tdLabel_4">序号</td>
      <td class="tdLabel_4">姓名</td>
      <td class="tdLabel_4">申请人</td>
      <td class="tdLabel_4">身份证号</td>
      <td class="tdLabel_4">诊疗标示</td>
      <td class="tdLabel_4">申请时间</td>
      <td class="tdLabel_4">打印状态</td>
      <td class="tdLabel_4">打印份数</td>
      <td class="tdLabel_4">申请原因</td>
      <td class="tdLabel_4">操作</td>
      </tr>
      <tbody id="tbody">

      </tbody>
     </table>
     <div class="pageList">
       <ul class="pagination clearfix" id="page_plus"></ul>
       <div class="pagination">
            <div>总共：<b id="totalPage">0</b> 条信息    当前页是第 <b id="currentPage">0/0</b>　页</div>
       </div>          
    </div>
      <!-- <div class="pages">
        <div id="Pagination"></div>
        <div class="searchPage">
          <span class="page-sum">共<strong id="ston_page_msg" class="allPage">0</strong>页</span>
          <span class="page-go">跳转<input type="text" class="number">页</span>
          <a href="javascript:;" class="page-btn">GO</a>
        </div>
    </div> -->

 	
 </div>
</div>
<!--页脚部分-->
 <%@include file="/WEB-INF/templates/common/footer.jsp"%>
 <script>
 	//查询打印申请信息
 	function queryPrint(pageNo,pageSize){
 		var timeStart=$("#timeStart").val();
 		//得到日期值并转化成日期格式，replace(//-/g, "//")是根据验证表达式把日期转化成长日期格式
 		var sDate = new Date(document.getElementById("timeStart").value.replace(/-/g, "/"));
 		var eDate = new Date(document.getElementById("timeEnd").value.replace(/-/g, "/"));
 		if(timeStart==""||timeStart==null){
 			layer.alert("申请时间不能为空!", {icon: 0});
 			$("#timeStart").addClass("input_change");
 			$("#timeStart").focus(function() { 
 			  	$(this).removeClass("input_change");	
 			});
 			return;
 		}else if(eDate!=""||eDate!=null){
 			if(sDate>eDate){
 				layer.alert("结束日期不能小于开始日期!", {icon: 0});
 				$("#timeEnd").addClass("input_change");
 				$("#timeEnd").focus(function() { 
 			  	$(this).removeClass("input_change");	
 			});
 				return;
 			}
 		}
 		
 		 var val=$('input:radio[name="printCheck"]:checked').val();
 		 var patientName=$("#patientName").val();
 		 var patientCard=$("#patientCard").val();
 		 var medicalRecord=$("#medicalRecord").val();
 		 var startTime=$("#timeStart").val();
 		 var endTime=$("#timeEnd").val();
 		 var applyName=$("#applyName").val();
 		 var applyCard=$("#applyCard").val();
 		$.ajax({
 			type:"post",
 			url:"${basePath}/print/getPrintList",
 			data:{patientName:patientName,patientCard:patientCard,startTime:startTime,endTime:endTime,status:val,
 				medicalRecord:medicalRecord,applyName:applyName,applyCard:applyCard,pageNo:pageNo,pageSize:pageSize},
 			success:function(data){
 				
 				var count=data.count;
 				
 				var printList=data.printList;
 				/* 
 			
 				
 				page(pageNo,count); */
 				$("#tbody").html("");
 				if(printList!=null && printList!=""){
 					initPage(count,pageSize,pageNo+1)
 					var html="";
 					for(var i in printList){
 						var applyPrint=printList[i];
 						html+="<tr>"+
 					     " <td class='tdLabel_5'>"+((parseInt(i)+1)+(parseInt(pageNo)*pageSize))+"</td>"+
 					     " <td class='tdLabel_5'>"+applyPrint.patientName+"</td>"+
 					    " <td class='tdLabel_5'>"+applyPrint.applyName+"</td>"+
 					     " <td class='tdLabel_5'>"+applyPrint.patientCard+"</td>"+
 					     " <td class='tdLabel_5' >"+applyPrint.medicalRecord+"</td>"+
 					     " <td class='tdLabel_5'>"+applyPrint.applyDate+"</td>"+
 					     " <td class='tdLabel_5' id='check"+applyPrint.applyPrintDetailId+"'>"+getPrintStatus(applyPrint.printStatus)+"</td>"+
 					    " <td class='tdLabel_5'>"+applyPrint.printCopies+"</td>"+
 					     " <td class='tdLabel_5'>"+getApplyReason(applyPrint.applyReason)+"</td>"+
 					     " <td class='tdLabel_5'><a id='TC1' onclick='print("+applyPrint.printStatus+","+applyPrint.printDetailId+")' >打印</a></td>"+
 					    "  </tr>";
 					    
 					}
 					$("#tbody").html(html);
 				}else{
 					$("#tbody").html("");
 					layer.alert("数据为空!", {icon: 5});
 					
 				}
 			}
 		})
 	}
 	
 	function print(status,printDetailId){
 		if(status==2){
 			layer.alert("此次申请已打印!", {icon: 0});
 			return;
 		}
 		window.location.href='${basePath}/print/getPrintInfo/'+printDetailId;  
 	}
 	

 	

 	
 	//审批状态
 	function getPrintStatus(status){
 		switch(status) {
 			case 1: 
 				return "未打印";
 			break; 
 			case 2: 
 				return "已打印";
 			break; 
 			case 3: 
 				return "打印中";
 			break; 
 			default: 
 				return "打印失败";
 		}
 	}
 	
 	//申请原因
 	function getApplyReason(status){
 		switch(status) {
 			case 1: 
 				return "医保";
 			break; 
 			case 2: 
 				return "司法";
 			break; 
 			case 3: 
 				return "门规";
 			break; 
 			default: 
 				return "其他";
 		}
 	}
 	
	//批量选中checkbox
 	function checkAll(obj){
 		var $this=$(obj);
 		if($this.is(':checked')){
 			$("input[type='checkbox'][name='checkOne']").each(function(){
 				$(this).attr("checked",true);
			});
 		}else{
 			$("input[type='checkbox'][name='checkOne']").each(function(){
 				$(this).attr("checked",false);
			});
 		}
 	} 
 	
 	//选中
 	function checkPrintAll(){
 		var applyPrinDetailId= getFormVals("checkOne");
 	
 		if(applyPrinDetailId==null || applyPrinDetailId==""){
 			layer.alert("请选择一条数据进行操作!", {icon: 0});
 		}else{
 			$.ajax({
 				type:"post",
 				data:{applyPrintDetailIds:applyPrinDetailId,status:2},
 				url:"http://localhost:8080/print/updateBatchApplyStatus",
 				success:function(data){
 					if(data=="success"){
 						var applyPrinDetails=applyPrinDetailId.split(",");
 						for(var i=0;i<applyPrinDetails.length;i++){
 							$("#check"+applyPrinDetails[i]).html("已批准");
 						}
 					}else{
 						
 					}
 				}
 			});
 		}
 	}
 	
function page(currentPage,totalCounts){
 		
 		var totalCounts = totalCounts;
 	 		var pageSize =10;
 	 		var totalPages = Math.ceil(totalCounts/pageSize);
 	 		var currentPage = currentPage;
 	 		$("#ston_page_msg").text(totalPages);
 	 		$(".number").keypress(function(event) {  
 	 			 var ev = event.which?event.which:window.event.keyCode;
 	 			  if(ev>=48&&ev<=57){
 	 				return true;  
 	 			  }else if(ev==8 || ev==13 || ev==46){
 	 				return true;  
 	 			  }else{
 	 				return false;
 	 			  } 
 	 		}).focus(function() {  
 	 			this.style.imeMode='disabled';  
 	 		});  
 	 		$("#Pagination").pagination(totalPages,{
 	 		current_page:currentPage,
 	 	  callback: function (page_index,jp) {
 	 	 	 //currentPage=page_index;
 	 		queryPrint(page_index,pageSize);
 	 	  } //PageCallback() 为翻页调用次函数。
 	 	  
 	 	  });
 		}
//分页
function initPage(totalCounts,pageSize,currentPage){
	 var visiblePages = 5;
	 var totalPages =Math.ceil(totalCounts/pageSize);
	 $("#totalPage").html(totalCounts);
     $("#currentPage").html(currentPage+"/"+totalPages);
	 $('#page_plus').jqPaginator({

	        totalCounts: totalCounts,
	        pageSize:pageSize,
	        visiblePages: visiblePages,
	        currentPage: currentPage,

	        first:'<li class="first"><a href="javascript:void(0);">首页</a></li>',
	        prev: '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
	        next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
	        last: '<li class="last"><a href="javascript:void(0);">末页</a></li>',
	        page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
	        onPageChange: function (page,type) {
	        	  /*  console.log(page) */
	     	  if(type !='init'){
	     		 queryPrint(page-1,pageSize);
				} 
	        }
	    });

}
 
 </script>
</body>
</html>
